package com.demo.mybatis.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.demo.mybatis.domain.MUserInformation;
import com.demo.mybatis.mapper.LoginRegisterMapper;
import com.demo.mybatis.service.MLoginRegisterService;
import com.demo.transactional.exception.TransationalException;

@Service("mLoginRegisterService")
public class MLoginRegisterImpl implements MLoginRegisterService {

	@Autowired
	private LoginRegisterMapper loginRegisterMapper;
	

	@Override
	public MUserInformation login(MUserInformation userInformation) {
		return loginRegisterMapper.doLogin(userInformation);
	}

	@Override
	@Transactional("testTransactionManager") //只需要添加这一个注解 ApplicaitionMain没有添加@EnableTransactionManagement开启事务
	public Integer delete(Long id) {
		Integer delete = loginRegisterMapper.delete(id);
		if(1==delete) {
			throw new TransationalException("抛出异常，数据回滚！");
		}
		return delete;
	}
	
}
